package org.grow.dealbill.controller;

import org.grow.common.entity.ExchangeScoreDto;
import org.grow.dealbill.dao.DealBillDao;
import org.grow.dealbill.entity.DealBill;
import org.grow.dealbill.service.ScoreFeignService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: xwg
 * @CreateDate: 21-8-12
 */

@RestController
@RequestMapping("/dbc")
public class DealBillController {
    @Autowired
    private DealBillDao dealBillDao;
    @Resource
    private ScoreFeignService scoreFeignService;

    @GetMapping("/unixTime")
    public String showUnixTime(){
        return System.currentTimeMillis()+"";
    }

    @PostMapping("/deal")
    public String deal(@RequestBody DealBill dealBill){
        dealBill.setDealBillId(0);
        System.out.println(dealBill);
        dealBillDao.save(dealBill);
        ExchangeScoreDto exchangeScoreDto = new ExchangeScoreDto();
//        exchangeScoreDto.setConsumerName(dealBill.getConsumerName());
        BeanUtils.copyProperties(dealBill,exchangeScoreDto);
        String s = scoreFeignService.exchangeScore(exchangeScoreDto);
        System.out.println(s);
//        使用java语言发http请求
//        todo：交易分数没有完成
        return "aaaa"+s;
    }
}
